﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mvc.XForms.Actions;

namespace Mvc.XForms.Controls.Settings {
	public class InputSettings : HtmlSettingsBase<InputSettings> {
		public IInput Input { get; private set; }

		public InputSettings(IInput input) {
			Input = input;
			HtmlControl = input;
			HtmlSettings = this;
		}

		public override string ToString() {
			return Input.ValidateThenRender();
		}

		public InputSettings Label(string label) {
			Input.Label = label;
			return this;
		}

		public InputSettings Help(string help) {
			Input.Help = help;
			return this;
		}

		public InputSettings Hint(string hint) {
			Input.Hint = hint;
			return this;
		}

		public InputSettings Appearance(Appearance appearance) {
			Input.Appearance = appearance;
			return this;
		}

		public InputSettings ReadOnly() {
			return ReadOnly(true);
		}

		public InputSettings ReadOnly(bool readOnly) {
			Input.ReadOnly = readOnly;
			if (readOnly)
				Input.CssClass.Add("readonly");
			return this;
		}

		public InputSettings Required() {
			return Required(true);
		}

		public InputSettings Required(bool required) {
			Input.Required = required;
			if (required)
				Input.CssClass.Add("required");
			return this;
		}

		public InputSettings ID(string clientID) {
			Input.ClientID = clientID;
			return this;
		}

		public InputSettings Action(XFormEvent xformsEvent, string jsFunction) {
			var action = new ActionAction() {
				Event = xformsEvent,
				JSFunction = jsFunction
			};
			Input.Actions.Add(action);
			return this;
		}
	}
}
